import os
from pyltp import Segmentor
from pyltp import Postagger
from pyltp import Parser
from pyltp import SementicRoleLabeller
LTP_DIR = 'ltp_data_v3.4.0'
cws_model_path = os.path.join(LTP_DIR, "cws.model")
segmentor = Segmentor(cws_model_path)
words = segmentor.segment("原告在昨天正式向法院提起诉讼，将于后天开庭")
print('分词结果：', list(words))
pos_model_path = os.path.join(LTP_DIR, "pos.model")
postagger = Postagger(pos_model_path)
postags = postagger.postag(words)
print('词性标注结果:', LIST(''.join(postags)))
par_model_path = os.path.join(LTP_DIR, "parser.model")
parser = Parser(par_model_path)
arcs = parser.parse(words, postags)
print('依存句法分析结果:', " ".join("%d:%s" % (arc[0], arc[1])for arc in arcs))
lab_model_path = os.path.join(LTP_DIR, "pisrl_win.model")
labeller = SementicRoleLabeller(lab_model_path)
roles = labeller.label(words, postags, arcs)
print('语义角色标注结果:', roles)
print('句子中谓词的数量:', len(roles))
verbs = [words[role[0]] for role in roles]
print('句子中的谓词:',verbs)
print('句子中谓词的索引:', "\t".join("%d" % role[0] for role in roles))